a, b, c = input().split()
id1=0 
id2=0
id3=0
m = ["zero","one","two","three","four","five","six","seven","eight","nine",]
def pr(n):
    fl=True
    for i in range(2, n):
        if n % i == 0:
            fl = False
            break
    return fl
if a in m and b in m and c in m:
    for i in range (len(m)):
        if (a!="zero" and b!="zero") or a!="zero":
            if a==m[i]:
                id1=i
                break
    for i in range (len(m)):
        if (a!="zero" and b!="zero") or a!="zero":
            if b==m[i]:
                id2=i
                break
    for i in range (len(m)):
        if (a!="zero" and b!="zero") or a!="zero":
            if c==m[i]:
                id3=i
                break
else:
    print("Wrong input")
if (a=="zero" and b=="zero") or a=="zero":
    print("Wrong input")

if (a in m and b in m and c in m) and ((a!="zero" and b!="zero") or a!="zero"):
    itog=int(str(id1) + str(id2) + str(id3))
    if pr(itog)==True:
        print(itog)
    else:
        x=y=0
        for r in range(itog+1, 998):
            if pr(r)==True:
                x=r
                break
        for l in range(0, itog):
            if pr(l)==True:
                y=l
        if (x-itog) >= (itog-y):
            print(y)
        else:
            print(x)
